package com.aisile.admin.service.imp;

import com.aisile.admin.mapper.AdSensitiveMapper;
import com.aisile.admin.service.AdSensitiveService;
import com.aisile.model.admin.dtos.SensitiveDto;
import com.aisile.model.admin.pojos.AdSensitive;
import com.aisile.model.common.dtos.ResponseResult;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class AdSensitiveServiceImpl extends ServiceImpl<AdSensitiveMapper,AdSensitive> implements AdSensitiveService {
    /**
     * 分页查询和搜索
     *
     * @param dto 用来存储分页数据 页数  总页数  和 搜索的neritic
     * @return
     */
    @Override
    public ResponseResult getPageList(SensitiveDto dto) {
        if (dto==null){
            return ResponseResult.okResult(2001, "不能为空!");
        }
        dto.checkParam();
        Page<AdSensitive> page = new Page<>(dto.getPage(), dto.getSize());
        LambdaQueryWrapper<AdSensitive> lambdaQueryWrapper = new LambdaQueryWrapper();
        if (StringUtils.isNotBlank(dto.getName())) {
            lambdaQueryWrapper.like(AdSensitive::getSensitives, dto.getName());
        }

        IPage result = page(page, lambdaQueryWrapper);
        return ResponseResult.okResult(result);
    }

    /**
     * service 添加方法
     *
     * @param sensitive 添加的数据
     * @return
     */
    @Override
    public ResponseResult adsensitive(AdSensitive sensitive) {
        if (sensitive==null){
            return ResponseResult.okResult(2001, "不能为空!");

        }
        this.adsensitive(sensitive);
        sensitive.setCreatedTime(new Date());
        return ResponseResult.errorResult(2000, "添加成功");
    }

    /**
     * 修改接口
     *
     * @param sensitive 存储修改的数据
     * @return
     */
    @Override
    public ResponseResult upsensitive(AdSensitive sensitive) {
        if (sensitive==null){
            return ResponseResult.okResult(2001, "不能为空!");
        }
        this.upsensitive(sensitive);
        return ResponseResult.errorResult(2000, "修改成功");
    }

    /**
     * 修改接口
     *
     * @param id 存储修改的数据
     * @return
     */
    @Override
    public ResponseResult deletesensitive(Integer id) {
        if (id==null){
            return ResponseResult.okResult(2001, "不能为空!");
        }
        this.deletesensitive(id);
        return ResponseResult.errorResult(2000, "删除成功");
    }

    @Override
    public ResponseResult getlist(Integer id) {
        if (id==null){
            return ResponseResult.okResult(2001, "不能为空!");
        }
        this.getlist(id);
        return ResponseResult.errorResult(2000, "查询成功");
    }

    @Override
    public ResponseResult deletesensitives(String[] ids) {
        if (ids==null){
            return ResponseResult.okResult(2001, "不能为空!");
        }
        this.deletesensitives(ids);
        return ResponseResult.errorResult(2000, "删除成功");
    }


}
